package com.hyf.popupdemo.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.PopupWindow;
import android.widget.Toast;

import com.hyf.popupdemo.DataSource;
import com.hyf.popupdemo.R;
import com.hyf.popupdemo.base.BaseActivity;
import com.hyf.popupdemo.support.PopWindowMenuHelper;
import com.hyf.popupdemo.support.PopupWindowMenu;

import java.util.List;

public class PopupMenuActivity extends BaseActivity {

    private List<PopupWindowMenu> list;

    private static final boolean showTriangle = true;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_popup_menu);
        setDisplayHomeAsUpEnabled();
        initView();
        initData();
        initListener();
    }

    private void initListener() {
    }

    private void initData() {
        list = DataSource.getMenuList();
    }

    private void initView() {
    }

    /**
     * 左上角
     *
     * @param view
     */
    public void clickLeftTop(View view) {
        new PopWindowMenuHelper.TopBuilder(getActivity(), list, view)
                .setShowTriangle(showTriangle)
                .setIsBlur(true)
                .setOnPopItemClickListener(menuItemClickListener).show();
    }

    /**
     * 右上角
     *
     * @param view
     */
    public void clickRightTop(View view) {
        new PopWindowMenuHelper.TopBuilder(getActivity(), list, view)
                .setShowTriangle(showTriangle)
                .setIsBlur(true)
                .setOnPopItemClickListener(menuItemClickListener).show();
    }

    /**
     * 左下角
     *
     * @param view
     */
    public void clickLeftBottom(View view) {
        new PopWindowMenuHelper.TopBuilder(getActivity(), list, view)
                .setShowTriangle(showTriangle)
                .setIsBlur(true)
                .setOnPopItemClickListener(menuItemClickListener).show();
    }

    /**
     * 右下角
     *
     * @param view
     */
    public void clickRightBottom(View view) {
        new PopWindowMenuHelper.TopBuilder(getActivity(), list, view)
                .setShowTriangle(showTriangle)
                .setIsBlur(true)
                .setOnPopItemClickListener(menuItemClickListener).show();
    }


    private PopWindowMenuHelper.OnItemClickListener menuItemClickListener = new PopWindowMenuHelper.OnItemClickListener() {
        @Override
        public void onClickPopwindowMenuItem(View view, PopupWindow window, int position) {
            Toast.makeText(getContext(), list.get(position).getTitle(), Toast.LENGTH_SHORT).show();
            window.dismiss();
        }
    };
}
